<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="类型">
              <a-select v-model="queryParam.type" placeholder="请选择类型">
                <a-select-option value="0">
                  政策文件类
                </a-select-option>
                <a-select-option value="1">
                  申请流程类
                </a-select-option>
                <a-select-option value="2">
                  需求咨询类
                </a-select-option>
                <a-select-option value="3">
                  建议意见类
                </a-select-option>
                <a-select-option value="4">
                  投诉举报类
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="标题">
              <j-input placeholder="请输入标题" v-model="queryParam.tittle"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="内容">
              <j-input placeholder="请输入内容" v-model="queryParam.content"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="关键字">
              <j-input placeholder="请输入关键字" v-model="queryParam.keywords"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">

          <a-button @click="showModal(record,2)" style="margin-right: 10px;">查看</a-button>
          <a-button type="primary" @click="showModal(record,1)" style="margin-right: 10px;">修改</a-button>

          <a-popconfirm
            cancel-text="取消"
            ok-text="确定"
            title="确定将该信息删除?"
            @confirm="getInfo(recordInfo)"
          >
            <a-button type="danger">作废</a-button>
          </a-popconfirm>
<!--          <a-button @click="showDeleteModal(record)" type="danger">作废</a-button>-->
<!--          <a-modal v-model="visible2" title="作废提示" @ok="getInfo(recordInfo)">-->
<!--            <p>是否对该条记录进行作废？作废后将无法恢复！</p>-->
<!--          </a-modal>-->
        </span>

        <span
          slot="filterDepositAttribute"
          slot-scope="powerType"
        >{{ powerType | filterDepositAttribute(powerType) }}</span>
      </a-table>
      <new-knowledge-model ref="newKnowledgeModel"></new-knowledge-model>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <cxmOrderManager-modal ref="modalForm" @ok="modalFormOk"></cxmOrderManager-modal> -->
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@comp/jeecg/JInput'
import moment from 'moment'
import { USER_INFO } from '@/store/mutation-types'
import Vue from 'vue'
import { getAction, httpAction } from '@api/manage'
import newKnowledgeModel from './newKnowledgeModel'

export default {
  name: 'knowledgeList',
  mixins: [JeecgListMixin],
  components: {
    JInput,
    moment,
    newKnowledgeModel
  },
  data() {
    return {
      description: 'cxm-订单管理页面',
      visible: false,
      visible2: false,
      record: '',
      value:'',
      // 表头
      loading: '',
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '类型',
          align: 'center',
          width: 160,
          dataIndex: 'type',
          scopedSlots: {
            customRender: 'filterDepositAttribute'
          }
        },
        {
          title: '标题',
          align: 'center',
          width: 280,
          dataIndex: 'tittle'
        },
        {
          title: '内容',
          align: 'center',
          dataIndex: 'content'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 260,
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],

      url: {
        list: '/cxm/knowledgeBase/list',
        delete: '/cxm/knowledgeBase/delete',
        deleteBatch: '/sale/cxmSaleIntention/deleteBatch',
        exportXlsUrl: 'sale/cxmSaleIntentionexportXls',
        importExcelUrl: 'sale/cxmSaleIntentionimportExcel'
      },
      recordInfo: ''
    }
  },
  methods: {
    showModal(record, type) {
      this.$refs.newKnowledgeModel.edit(record, type)
      // this.visible2 = true
      // this.recordInfo = record
    },
    showDeleteModal(record) {
      this.visible2 = true
      this.recordInfo = record.id
    },
    getInfo() {
      console.log(this.recordInfo)
      this.axios.delete('/cxm/knowledgeBase/delete?id=' + this.recordInfo).then(res => {
        let rs = res.result
        console.log(rs)
        this.visible2 = false
        this.$message.success(res.message)
        this.loadData()
      }).catch(err => {
        // this.expRoute("2",err.message)
      })
    }
  },
  filters: {
    filterTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    filterDepositAttribute(depositAttribute) {
      console.log(depositAttribute)
      if (depositAttribute === '0') {
        return '政策文件类'
      } else if (depositAttribute === '1') {
        return '申请流程类'
      } else if (depositAttribute === '2') {
        return '需求咨询类'
      } else if (depositAttribute === '3') {
        return '建议意见类'
      } else if (depositAttribute === '4') {
        return '投诉举报类'
      }

    }
  }
}
</script>
<style scoped>

</style>
